package com.basic.business.controller;

import com.basic.business.common.config.ValidationGroups;
import com.basic.business.model.dto.SysDictDto;
import com.basic.business.model.vo.SysDictVo;
import com.basic.business.service.SysDictService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import com.github.pagehelper.*;

import javax.annotation.Resource;
import javax.validation.constraints.Min;

/**
 * 字典表(SysDict)表控制层
 *
 * @author huage
 * @since 2021-07-20 10:57:08
 */
@Api(tags = "字典数据配置")
@RestController
@RequestMapping("/sysDict")
public class SysDictController {

    @Resource
    private SysDictService sysDictService;

    @ApiOperation(value = "通过id查询单条数据 字典表")
    @ApiImplicitParam(name = "id", value = "SysDict id", dataType = "Long", paramType = "path", required = true)
    @GetMapping("/findById/{id}")
    public SysDictVo findById(@Min(value = 1) @PathVariable(value = "id") Long id) {
        return this.sysDictService.findById(id);
    }

    @ApiOperation(value = "查询多条数据 字典表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "path", required = true),
            @ApiImplicitParam(name = "pageSize", value = "查询条数", dataType = "int", paramType = "path", required = true)
    })
    @PostMapping(value = "/findPageList/{pageNum}/{pageSize}")
    public PageInfo<SysDictVo> findPageList(@RequestBody SysDictDto sysDictDto, @PathVariable(value = "pageNum") int pageNum, @PathVariable(value = "pageSize") int pageSize) {
        return this.sysDictService.findPageList(sysDictDto, pageNum, pageSize);
    }

    @ApiOperation(value = "新增数据 字典表")
    @PostMapping("/add")
    public SysDictVo add(@Validated(ValidationGroups.Save.class) @RequestBody SysDictDto sysDictDto) {
        return this.sysDictService.add(sysDictDto);
    }

    @ApiOperation(value = "修改数据 字典表Dto")
    @ApiImplicitParam(name = "id", value = "SysDict id", dataType = "long", paramType = "query", required = true)
    @PatchMapping("/modify")
    public SysDictVo modify(@Validated(ValidationGroups.Update.class) @RequestBody SysDictDto sysDictDto) {
        return this.sysDictService.modify(sysDictDto);
    }

    @ApiOperation(value = "通过主键删除数据 字典表")
    @ApiImplicitParam(name = "id", value = "SysDict id", dataType = "Long", paramType = "path", required = true)
    @DeleteMapping("/remove/{id}")
    public boolean remove(@Min(value = 1) @PathVariable(value = "id") Long id) {
        return this.sysDictService.remove(id);
    }

}
